/*
 * MarketGUI.java
 *
 */
package market;

import java.util.ArrayList;
import java.util.Timer;

/*jms*/

public class MarketGUI extends javax.swing.JFrame {

    private Timer daTimer;
    private PPriceEvolution pE;
    public static final StockService service = new StockService();
    private ArrayList daList;

    /**
     * Creates new form MarketGUI
     */
    public MarketGUI() {
        daList = service.getDaList();
        initComponents();

        this.pE = new PPriceEvolution(jListEvent, daList);

        //Cr�ation d'un timer qui va modifier les prix toutes les minutes
        this.daTimer = new Timer();
        this.daTimer.schedule(this.pE, 0, 60 * 100);
        System.out.println("Market started!!");
    }

    public static void main(String args[]) {

         new MarketGUI().setVisible(true);
      

    }

  

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jPanelBody = new javax.swing.JPanel();
        jScrollPaneEvent = new javax.swing.JScrollPane();
        jListEvent = new javax.swing.JList();
        jButtonClear = new javax.swing.JButton();
        jButtonSetStocksPrices = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jPanelBody.setBorder(javax.swing.BorderFactory.createTitledBorder("Events list"));
        jScrollPaneEvent.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jListEvent.setBackground(java.awt.SystemColor.controlHighlight);
        jListEvent.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jListEvent.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPaneEvent.setViewportView(jListEvent);

        jButtonClear.setText("Clear events list");
        jButtonClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonClearActionPerformed(evt);
            }
        });

        jButtonSetStocksPrices.setText("Set stocks prices");
        jButtonSetStocksPrices.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSetStocksPricesActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanelBodyLayout = new org.jdesktop.layout.GroupLayout(jPanelBody);
        jPanelBody.setLayout(jPanelBodyLayout);
        jPanelBodyLayout.setHorizontalGroup(
            jPanelBodyLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelBodyLayout.createSequentialGroup()
                .addContainerGap()
                .add(jPanelBodyLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPaneEvent, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 530, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanelBodyLayout.createSequentialGroup()
                        .add(jButtonSetStocksPrices, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 159, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButtonClear)))
                .addContainerGap())
        );
        jPanelBodyLayout.setVerticalGroup(
            jPanelBodyLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelBodyLayout.createSequentialGroup()
                .add(jScrollPaneEvent, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanelBodyLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButtonClear)
                    .add(jButtonSetStocksPrices))
                .addContainerGap())
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelBody, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jPanelBody, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Call the run method of the priceEvolution object
     *
     * @see PriceEvolution
     */
    private void jButtonSetStocksPricesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSetStocksPricesActionPerformed

        this.pE.run();
    }//GEN-LAST:event_jButtonSetStocksPricesActionPerformed

    /**
     * This method clears the arrayList containing the logs
     */
    private void jButtonClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonClearActionPerformed
        this.pE.getLogList().clear();
        this.pE.getLogList().add("Clear");
        this.jListEvent.setListData(this.pE.getLogList().toArray());
    }//GEN-LAST:event_jButtonClearActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonClear;
    private javax.swing.JButton jButtonSetStocksPrices;
    private javax.swing.JList jListEvent;
    private javax.swing.JPanel jPanelBody;
    private javax.swing.JScrollPane jScrollPaneEvent;
    // End of variables declaration//GEN-END:variables
}
